<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <title> ztree demo </title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet"  href="/layui/css/layui.css"/>
  <link rel="stylesheet" href="/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
  <style>
    body {
      background-color: white;
      margin: 0;
      padding: 0;
      text-align: center;
    }

    div, p, table, th, td {
      list-style: none;
      margin: 0;
      padding: 0;
      color: #333;
      font-size: 12px;
      font-family: dotum, Verdana, Arial, Helvetica, AppleGothic, sans-serif;
    }
  </style>
  <script type="text/javascript" src="/ztree/js/jquery-1.4.4.min.js"></script>
  <script  src="/layui/layui.js"></script>
  <script src="/plugins/js/common.js"></script>
  <script type="text/javascript" src="/ztree/js/jquery.ztree.core.js"></script>
  <script type="text/javascript" src="/ztree/js/jquery.ztree.excheck.js"></script>
  <script type="text/javascript" src="/ztree/js/jquery.ztree.exedit.js"></script>
  <script type="text/javascript" th:inline="javascript">
  var layer;
  layui.use("layer",function(){
  	layer=layui.layer;
  });  
    var zTree;
    var setting = {
      view: {
			selectedMulti: false,
			dblClickExpand: false
	  },
	  async:{enable: true,url: getUrl},
      data: {
        simpleData: {
          enable: true,
          idKey: "id",
          pIdKey: "pId"
        }
      },
      callback: {
    	  beforeDrag: beforeDrag,
    	  onClick: zTreeOnClick
      }
	};
    
    function beforeDrag(treeId, treeNodes) {
		return false;
	}
    
   
	
	function getUrl(treeId, treeNode) {
		return "/area/selectAreaInfoListByPid?pId="+treeNode.id;
	}
    
    function zTreeOnClick(event, treeId, treeNode){
    	$('#areaCode', parent.document).val(treeNode.code);
    	$('#areaName', parent.document).val(treeNode.name);
    	var index = parent.layer.getFrameIndex(window.name);
    	parent.layer.close(index)
    }
    
    var zNodes = JSON.parse([[${areaListJson}]]);
    for(var j=0 ; j<zNodes.length; j++){//遍历目录节点，设置isParent属性为true;
  	  zNodes[j].isParent = true;
    }
    $(document).ready(function () {
      var t = $("#tree");
      zTree = $.fn.zTree.init(t, setting, zNodes);
    });

    function loadReady() {
      var bodyH = demoIframe.contents().find("body").get(0).scrollHeight,
        htmlH = demoIframe.contents().find("html").get(0).scrollHeight,
        maxH = Math.max(bodyH, htmlH), minH = Math.min(bodyH, htmlH),
        h = demoIframe.height() >= maxH ? minH : maxH;
      if (h < 530) h = 530;
      demoIframe.height(h);
    }
    
    
    function refresh(pId){
    	var node = zTree.getNodeByParam("id", pId, null);
    	zTree.reAsyncChildNodes(node, "refresh");
    }
    
  </script>
</head>

<body>
	<ul id="tree" class="ztree" style="width:260px; overflow:auto;"></ul>
</body>	
</html>
